<template>
  <div class="main">
    <mine-title>模型详情</mine-title>

    <!-- 模型详情 -->
    <div class="top">
      <div
        class="each-top-row"
        v-for="(item, index) in modelDetail"
        :key="index"
      >
        <div
          class="each-top-part"
          v-for="(itemSec, indexSec) in item"
          :key="indexSec"
        >
          <div :class="`each-top-part-name col-${indexSec}`">
            {{ itemSec.name }}：
          </div>
          <div class="each-top-part-value">
            <!-- 运行状态 -->
            <div class="flex-row" v-if="itemSec.attr === 'status'">
              <status-text
                :value="modelDetailData[itemSec.attr]"
                :dict="statusList"
              ></status-text>
              <div v-if="modelDetailData.projectType !== 'data_unsupervised'">
                <mine-button
                  size="mini"
                  type="danger"
                  secondary
                  v-if="statusPublished(modelDetailData)"
                  @click="publishOff"
                  ><i class="iconfont icon-arrow-down-line"></i>下线
                </mine-button>
                <mine-button
                  size="mini"
                  type="primary"
                  v-if="
                    statusUnpublish(modelDetailData) &&
                    (isPublish(modelDetailData) || isLoadmodel(modelDetailData))
                  "
                  @click="publishOn(modelDetailData)"
                  ><i class="iconfont icon-release-line"></i>发布
                </mine-button>
              </div>
            </div>
            <!-- 模型进度 -->
            <div v-else-if="itemSec.attr === 'progressRate'">
              <div class="flex-row">
                <status-text
                  :value="modelDetailData[itemSec.attr]"
                  :dict="progressRate"
                ></status-text>
                <div v-if="modelDetailData.projectType === 'data_unsupervised'">
                  <mine-button
                    size="mini"
                    type="primary"
                    secondary
                    @click="downloadUnFile()"
                    v-if="isPublish(modelDetailData)"
                    :loading="downloading"
                    ><i class="iconfont icon-download-line"></i>生成
                  </mine-button>
                  <mine-button
                    size="mini"
                    type="primary"
                    secondary
                    @click="checkProgress()"
                    v-if="!isTrain(modelDetailData)"
                    >进入
                  </mine-button>
                </div>
                <div v-else-if="modelDetailData.projectType === 'other'">
                  <mine-button
                    size="mini"
                    type="primary"
                    secondary
                    @click="exportModel()"
                    v-if="isLoadmodel(modelDetailData)"
                    :loading="downloading"
                    ><i class="iconfont icon-download-line"></i>生成
                  </mine-button>
                </div>
                <div v-else>
                  <mine-button
                    size="mini"
                    type="primary"
                    secondary
                    @click="exportModel()"
                    v-if="isPublish(modelDetailData)"
                    :loading="downloading"
                    ><i class="iconfont icon-download-line"></i>生成
                  </mine-button>
                  <mine-button
                    size="mini"
                    type="primary"
                    secondary
                    @click="checkProgress()"
                    v-if="!isTrain(modelDetailData)"
                    >进入
                  </mine-button>
                </div>
              </div>
            </div>
            <!-- 模型类型 -->
            <div v-else-if="itemSec.attr === 'projectType'">
              {{
                $common.fetchSingleWord({
                  val: modelDetailData[itemSec.attr],
                  dict: classifyList,
                  flag: "--",
                })
              }}
            </div>
            <!-- 实现方式 -->
            <div v-else-if="itemSec.attr === 'modelFileType'">
              {{
                $common.fetchSingleWord({
                  val: modelDetailData[itemSec.attr],
                  dict: implementationModeList,
                  flag: "--",
                })
              }}
            </div>
            <!-- 其他字段 -->
            <div v-else>
              {{
                modelDetailData[itemSec.attr]
                  ? modelDetailData[itemSec.attr]
                  : "--"
              }}
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 模型预测 -->
    <div
      class="bottom"
      v-if="
        modelDetailData.projectType !== 'data_unsupervised' &&
        modelDetailData.status == 'published'
      "
    >
      <div class="bottom-title">
        <h2 class="bottom-title-name">模型测试</h2>
        <!-- 发布了，才能新建预测 -->
        <!-- <div class="bottom-title-button">
          <mine-button
            type="primary"
            @click="newForecast"
            v-if="statusPublished(modelDetailData)"
            ><i class="iconfont icon-add-line"></i>新建测试
          </mine-button>
          <mine-button
            type="primary"
            @click="getForecastData()"
            v-if="statusPublished(modelDetailData)"
            secondary
            ><i class="iconfont icon-reset-line"></i>刷新
          </mine-button>
        </div> -->
      </div>
      <!-- <el-table
        class="bottom-table-area"
        :data="forecastTableData"
        style="width: 100%"
        v-loading="loading"
      >
        <el-table-column prop="taskName" :show-overflow-tooltip="true">
          <template slot="header">
            <span>测试任务名称</span>
            <mine-table-search
              @searchSubmit="searchSubmit"
              name="taskName"
            ></mine-table-search>
          </template>
        </el-table-column>

        <el-table-column
          prop="createTime"
          label="创建时间"
          sortable
        ></el-table-column>
        <el-table-column prop="endTime" label="完成时间" sortable>
          <template slot-scope="scope">
            {{ scope.row.endTime ? scope.row.endTime : "--" }}
          </template>
        </el-table-column>

        <el-table-column prop="status">
          <template slot="header">
            <span>运行状态</span>
            <mine-table-screen
              :isRadio="true"
              @screenSubmit="screenSubmit"
              name="status"
              :list="forecastStatusList"
            ></mine-table-screen>
          </template>
          <template slot-scope="scope">
            <status-text
              :value="scope.row.status"
              :dict="forecastStatusList"
            ></status-text>
          </template>
        </el-table-column>

        <el-table-column prop="date" label="操作">
          <template slot-scope="scope">
            <mine-button
              v-if="scope.row.status == 'complete'"
              type="text"
              size="mini"
              @click="downloadForecast(scope.row)"
              :loading="scope.row.loading"
              >生成预测结果
            </mine-button>
            <div v-else>--</div>
          </template>
        </el-table-column>
      </el-table>

      <mine-pagination
        @numberChange="pageNumChange"
        :total="totalPageNum"
        :page-size="pageSize"
        :current-page="currentPage"
      ></mine-pagination> -->
      <TextForcast></TextForcast>
    </div>
    <mine-dialog
      :appendToBody="true"
      :dialogFormVisible="flag"
      :width="'1000px'"
      :modalFlag="modalFlag"
      :title="title"
      :showClose="showClose"
      @close="close"
    >
      <publish-modal
        ref="publishModal"
        v-if="assembly === '发布模型'"
        slot="option"
        @close="close"
        :modelId="modelId"
        :projectId="projectId"
        @callback="pushlishOnCallback"
        :fullscreenLoading="fullscreenLoading"
      ></publish-modal>
    </mine-dialog>
  </div>
</template>

<script>
import { mappingMixins, modalMixins } from "./mixins";
import statusText from "./components/statusText";
import publishModal from "./components/publishModal";
import { QWebChannel } from "@/modules/index/utils/qwebchannel.js";
import { Loading } from "element-ui";
import TextForcast from "./components/textForcast.vue";

export default {
  mixins: [mappingMixins, modalMixins],

  components: { statusText, publishModal, TextForcast },

  data: function () {
    return {
      modelDetail: [
        // 模型详情数据项
        [
          { name: "模型名称", attr: "projectName" },
          { name: "运行状态", attr: "status" },
          {
            name: "模型进度",
            attr: "progressRate",
          },
        ],
        [
          { name: "创建人", attr: "creater" },
          { name: "创建时间", attr: "createTime" },
          {
            name: "模型类型",
            attr: "projectType",
          },
        ],
        [
          { name: "算法名称", attr: "arithmetic" },
          // {
          //   name: "算法类型",
          //   attr: "modelType",
          // },
          // {name: "实现方式", attr: "modelFileType"}
        ],
        [
          { name: "关联数据集", attr: "modelName" },
          {
            name: "数据集创建时间",
            attr: "setCreateTime",
          },
          { name: "API地址", attr: "api" },
        ],
        [{ name: "模型描述", attr: "projectDesc" }],
      ],
      originModelDetailData: {}, // 模型列表的单条数据
      modelDetailData: {}, // 模型详情数据
      forecastTableData: [], // 预测的表格数据
      forecastTableHeight: 300, // 表格的高度

      pageSize: 10, // 表格一页展示的数据量
      totalPageNum: 0, // 表格总的数据量
      currentPage: 1, // 表格当前的页数
      loading: false, // 表格loading是否显示
      taskName: "", // 搜索的任务名称
      taskStatus: "", // 搜索的任务类型
      modelType: "", // 模型类型
      downloading: false,
      fullscreenLoading: false, // 全屏禁用的loading

      distinguishType: "single", // 页签切换开关
      labelWidth: "150px",
      form: {},
      analysisStatus: 0,
      fileType: ".txt,.csv,.xls,.xlsx",
      taskId: "",
      singleResult: "",
      mAnalysisStatus: 0,
    };
  },

  computed: {
    projectId() {
      return this.modelDetailData.id || "";
    },
    modelId() {
      return this.modelDetailData.modelId || "";
    },
  },

  mounted: function () {
    // 设置面包屑导航
    this.$store.commit("SET_BREADCRUMB", [
      { title: "前沿算法诊断", path: "/model/list" },
      { title: "模型详情", path: "" },
    ]);
    this.init();
  },

  methods: {
    // 初始化
    async init() {
      this.getModelList();
      // setTimeout(async () => {
      //   this.getForecastData(true);
      // }, 200);
    },

    // 获取模型列表
    async getModelList() {
      var id = this.$route.query.id;
      var params = { id: id };
      let res = {};
      let _self = this;
      try {
        if (_self.$qwebUtil.isQtClient) {
          const uuid = _self.$qwebUtil.generateRandomUUID();
          let sendObject;
          /* eslint-disable-next-line */
          const channel = new QWebChannel(
            window.qt.webChannelTransport,
            async function (channel) {
              sendObject = channel.objects.sendObject;
              // receivedJSON 修改此处发送请求参数
              const receivedJSON = {
                RequestUrl: "/project/" + params.id,
                RequestMethod: "get",
                ContentType: "application/json;charset=UTF-8",
                RequestBody: {},
                isStringParam: false,
                requestId: uuid,
              };
              await send();
              await _self.$qwebUtil.receive(sendObject, receivedJSON);
              // console.error('received','/feCanvas/pageList')
            }
          );
          /* eslint-disable-next-line */
          async function send() {
            sendObject.sendMessage.connect(function (data) {
              if (!data) {
                console.error("No data received.");
              }
              res = JSON.parse(data);
              const result = res.response || {};
              // update the followings
              if (result.success && res.webInfo.requestId == uuid) {
                _self.getModelDetailData();
                const data = result.data || {};
                _self.originModelDetailData = { ...data };
                _self.modelDetailData = data;
                _self.modelType = result.data.projectType;
              }
            });
          }
        } else if (this.$webview2.isWPF) {
          const uuid = this.$webview2.generateRandomUUID();
          await this.$webview2.sendWebView2(
            "/project/" + params.id,
            "get",
            "application/json;charset=UTF-8",
            {},
            false,
            uuid
          );
          await window.chrome.webview.addEventListener(
            "message",
            (e) => {
              let res = e.data.response;
              // TODO： 定制后台数据处理
              if (res.status === 200 && e.data.webInfo.requestId === uuid) {
                const data = res.data || {};
                this.originModelDetailData = { ...data };
                this.modelDetailData = data;
                this.modelType = res.data.projectType;
                this.getModelDetailData();
              }
            },
            { once: true }
          );
        } else {
          const res = await this.$store.dispatch(
            "modelManageModelDetail",
            params
          );
          const result = res.data || {};
          if (result.success) {
            const data = result.data || {};
            this.originModelDetailData = { ...data };
            this.modelDetailData = data;
            this.modelType = res.data.data.projectType;
            this.getModelDetailData();
          }
        }
      } catch (e) {
        console.error(e);
      }
    },

    // 获取模型详情数据
    getModelDetailData: async function () {
      var id = this.$route.query.id;
      var params = { id };
      try {
        let res = {};
        let _self = this;
        if (_self.$qwebUtil.isQtClient) {
          const uuid = _self.$qwebUtil.generateRandomUUID();
          let sendObject;
          /* eslint-disable-next-line */
          const channel = new QWebChannel(
            window.qt.webChannelTransport,
            async function (channel) {
              sendObject = channel.objects.sendObject;
              // receivedJSON 修改此处发送请求参数
              const receivedJSON = {
                RequestUrl:
                  "/training-model-data/find-by-projectId/" + params.id,
                RequestMethod: "get",
                ContentType: "application/json;charset=UTF-8",
                RequestBody: {},
                isStringParam: false,
                requestId: uuid,
              };
              await send();
              await _self.$qwebUtil.receive(sendObject, receivedJSON);
              // console.error('received','/feCanvas/pageList')
            }
          );
          /* eslint-disable-next-line */
          async function send() {
            sendObject.sendMessage.connect(function (data) {
              if (!data) {
                console.error("No data received.");
              }
              res = JSON.parse(data);
              const result = res.response || {};
              // alert(JSON.stringify(result)); // 这里没触发，但日志有

              if (result.success && res.webInfo.requestId == uuid) {
                // update the followings
                let resultData = result.data || {};
                resultData.setCreateTime = resultData.createTime;
                for (var i in resultData) {
                  if (!_self.modelDetailData[i]) {
                    _self.$set(_self.modelDetailData, i, resultData[i]);
                  }
                }
                _self.modelDetailData.modelId = resultData.id || "";
              }
            });
          }
        } else if (this.$webview2.isWPF) {
          const uuid = this.$webview2.generateRandomUUID();
          await this.$webview2.sendWebView2(
            "/training-model-data/find-by-projectId/" + params.id,
            "get",
            "application/json;charset=UTF-8",
            {},
            false,
            uuid
          );
          await window.chrome.webview.addEventListener(
            "message",
            (e) => {
              //   console.log(res);
              // TODO： 定制后台数据处理
              if (
                e.data.response.status === 200 &&
                e.data.webInfo.requestId === uuid
              ) {
                let res = e.data.response;
                var data = res.data || {};
                data.setCreateTime = data.createTime;
                for (var i in data) {
                  if (!this.modelDetailData[i]) {
                    this.$set(this.modelDetailData, i, data[i]);
                  }
                }
                this.modelDetailData.modelId = data.id || "";
              }
            }
            // { once: true }
          );
        } else {
          const res = await this.$store.dispatch(
            "modelManageTrainingModelDataFindByProjectId",
            params
          );
          var result = res.data || {};
          if (result.success) {
            var data = result.data || {};
            data.setCreateTime = data.createTime;
            for (var i in data) {
              if (!this.modelDetailData[i]) {
                this.$set(this.modelDetailData, i, data[i]);
              }
            }
            this.modelDetailData.modelId = data.id || "";
          }
        }
      } catch (e) {
        console.error(e);
      }
    },

    // 获取模型预测数据
    // async getForecastData(flag) {
    //   if (flag) {
    //     this.currentPage = 1;
    //   }
    //   var params = {
    //     page: this.currentPage,
    //     pageSize: this.pageSize,
    //     taskName: this.taskName,
    //     status: this.taskStatus,
    //     project_id: this.projectId,
    //   };
    //   this.loading = true;
    //   try {
    //     let res = {};
    //     let _self = this;
    //     if (_self.$qwebUtil.isQtClient) {
    //       const uuid = _self.$qwebUtil.generateRandomUUID();
    //       let sendObject;
    //       /* eslint-disable-next-line */
    //       const channel = new QWebChannel(
    //         window.qt.webChannelTransport,
    //         async function (channel) {
    //           sendObject = channel.objects.sendObject;
    //           // receivedJSON 修改此处发送请求参数
    //           const receivedJSON = {
    //             RequestUrl: "/predicttask/predict-task/search",
    //             RequestMethod: "post",
    //             ContentType: "application/json;charset=UTF-8",
    //             RequestBody: params,
    //             isStringParam: false,
    //             requestId: uuid,
    //           };
    //           await send();
    //           await _self.$qwebUtil.receive(sendObject, receivedJSON);
    //           // console.error('received','/feCanvas/pageList')
    //         }
    //       );
    //       /* eslint-disable-next-line */
    //       async function send() {
    //         sendObject.sendMessage.connect(function (data) {
    //           if (!data) {
    //             console.error("No data received.");
    //           }
    //           res = JSON.parse(data);
    //           const result = res.response || {};
    //           // update the followings
    //           if (result.success && res.webInfo.requestId == uuid) {
    //             const data = result.data || {};
    //             var list = data.list || {};
    //             _self.forecastTableData = list;
    //             _self.totalPageNum = data.rowCount || 0;
    //           } else {
    //             _self.tableData = [];
    //             _self.totalPageNum = 0;
    //           }
    //         });
    //       }
    //     } else if (this.$webview2.isWPF) {
    //       const uuid = this.$webview2.generateRandomUUID();
    //       await this.$webview2.sendWebView2(
    //         "/predicttask/predict-task/search",
    //         "post",
    //         "application/json;charset=UTF-8",
    //         params,
    //         false,
    //         uuid
    //       );
    //       await window.chrome.webview.addEventListener(
    //         "message",
    //         (e) => {
    //           let res = e.data.response;
    //           // TODO： 定制后台数据处理
    //           if (res.status === 200 && e.data.webInfo.requestId === uuid) {
    //             const data = res.data || {};
    //             var list = data.list || {};
    //             this.forecastTableData = list;
    //             this.totalPageNum = data.rowCount || 0;
    //           } else {
    //             this.tableData = [];
    //             this.totalPageNum = 0;
    //           }
    //         },
    //         { once: true }
    //       );
    //     } else {
    //       const res = await this.$store.dispatch(
    //         "modelManagePredictTaskSearch",
    //         params
    //       );
    //       const result = res.data || {};
    //       if (result.success) {
    //         const data = result.data || {};
    //         var list = data.list || {};
    //         this.forecastTableData = list;
    //         this.totalPageNum = data.rowCount || 0;
    //       } else {
    //         this.tableData = [];
    //         this.totalPageNum = 0;
    //       }
    //     }
    //   } catch (e) {
    //     console.error(e);
    //   }
    //   this.loading = false;
    // },

    // 表头搜索
    // searchSubmit(value) {
    //   if (value.key === "taskName") {
    //     this.taskName = value.value;
    //   }
    //   this.currentPage = 1;
    //   this.getForecastData();
    // },

    // 表头筛选
    // screenSubmit(value) {
    //   if (value.key == "status") {
    //     this.taskStatus = value.value;
    //   }
    //   this.currentPage = 1;
    //   this.getForecastData();
    // },

    // 表格换页
    // pageNumChange(value) {
    //   if (value.flag == "pageSize") {
    //     this.currentPage = 1;
    //   }
    //   this[value.flag] = value[value.flag];
    //   this.getForecastData();
    // },

    // 下载预测
    // downloadForecast: async function (val) {
    //   this.$set(val, "loading", true);
    //   const params = {
    //     id: val.id,
    //   };
    //   try {
    //     let res = {};
    //     let _self = this;
    //     if (_self.$qwebUtil.isQtClient) {
    //       const uuid = _self.$qwebUtil.generateRandomUUID();
    //       let sendObject;
    //       /* eslint-disable-next-line */
    //       const channel = new QWebChannel(
    //         window.qt.webChannelTransport,
    //         async function (channel) {
    //           sendObject = channel.objects.sendObject;
    //           // receivedJSON 修改此处发送请求参数
    //           const receivedJSON = {
    //             RequestUrl: `/predicttask/predict-task/${params.id}/getResultUrl`,
    //             RequestMethod: "get",
    //             ContentType: "application/json;charset=UTF-8",
    //             RequestBody: {},
    //             isStringParam: false,
    //             requestId: uuid,
    //           };
    //           await send();
    //           await _self.$qwebUtil.receive(sendObject, receivedJSON);
    //           // console.error('received','/feCanvas/pageList')
    //         }
    //       );
    //       /* eslint-disable-next-line */
    //       async function send() {
    //         sendObject.sendMessage.connect(function (data) {
    //           // if (!data) {
    //           //   console.error("No data received.");
    //           // }
    //           // res = JSON.parse(data);
    //           // const result = res.response || {};
    //           // // update the followings
    //           // if (result.success && res.webInfo.requestId == uuid) {
    //           // } else {
    //           // }
    //         });
    //       }
    //     } else if (this.$webview2.isWPF) {
    //       const uuid = this.$webview2.generateRandomUUID();
    //       await this.$webview2.sendWebView2(
    //         `/predicttask/predict-task/${params.id}/getResultUrl`,
    //         "get",
    //         "application/json;charset=UTF-8",
    //         {},
    //         false,
    //         uuid
    //       );
    //     } else {
    //       await this.$store.dispatch(
    //         "proAdminPredicttaskPredictTaskIdGetResultUrl",
    //         params
    //       );
    //     }
    //   } catch (e) {
    //     console.error(e);
    //   }
    //   this.$set(val, "loading", false);
    // },

    // 新建预测
    // newForecast: function () {
    //   if (!this.statusPublished(this.modelDetailData)) {
    //     this.$message.warning("请先发布模型");
    //     return;
    //   }
    //   var id = this.$route.query.id;
    //   const query = {
    //     id,
    //     type: this.modelType,
    //   };
    //   if (this.modelDetailData.modelFileType) {
    //     query.modelFileType = this.modelDetailData.modelFileType;
    //   }
    //   this.$router.push({
    //     path: "/model/forecast",
    //     query,
    //   });
    // },

    // 下线
    publishOff() {
      // 禁用两秒
      let fullLoading = Loading.service({
        lock: true,
        text: "下线中",
      });
      setTimeout(() => {
        fullLoading.close();
      }, 2000);

      const modelName = this.modelDetailData.projectName || "";
      this.$mineConfirm(`确认要下线${modelName}`, "确认要下线", {
        confirmButtonText: "下线",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const params = {
            modelId: this.modelId,
          };
          let publishTaskId = "";
          let stopParams = {};
          this.loading = true;
          try {
            let res = {};
            let _self = this;
            if (_self.$qwebUtil.isQtClient) {
              const uuid = _self.$qwebUtil.generateRandomUUID();
              let sendObject;
              /* eslint-disable-next-line */
              const channel = new QWebChannel(
                window.qt.webChannelTransport,
                async function (channel) {
                  sendObject = channel.objects.sendObject;
                  // receivedJSON 修改此处发送请求参数
                  const receivedJSON = {
                    RequestUrl: `/publishtask/publish-task-data/find-by-model/${params.modelId}`,
                    RequestMethod: "get",
                    ContentType: "application/json;charset=UTF-8",
                    RequestBody: {},
                    isStringParam: false,
                    requestId: uuid,
                  };
                  await send();
                  await _self.$qwebUtil.receive(sendObject, receivedJSON);
                  // console.error('received','/feCanvas/pageList')
                }
              );
              /* eslint-disable-next-line */
              async function send() {
                sendObject.sendMessage.connect(function (data) {
                  if (!data) {
                    console.error("No data received.");
                  }
                  res = JSON.parse(data);
                  const result = res.response || {};
                  // update the followings
                  if (result.success && res.webInfo.requestId == uuid) {
                    const data = result.data || {};
                    publishTaskId = data.id;
                  } else {
                    _self.$message.error(result.msg);
                  }
                  if (!publishTaskId) {
                    _self.$message.error("下线失败");
                    _self.loading = false;
                    return;
                  }
                  stopParams = {
                    publishTaskId: publishTaskId,
                  };
                  //   第二个接口开始，下线
                  _self.handleOffLine(stopParams);
                });
              }
            } else if (this.$webview2.isWPF) {
              const uuid = this.$webview2.generateRandomUUID();
              await this.$webview2.sendWebView2(
                `/publishtask/publish-task-data/find-by-model/${params.modelId}`,
                "get",
                "application/json;charset=UTF-8",
                {},
                false,
                uuid
              );
              await window.chrome.webview.addEventListener(
                "message",
                (e) => {
                  let res = e.data.response;
                  // TODO： 定制后台数据处理
                  if (res.status === 200 && e.data.webInfo.requestId === uuid) {
                    const data = res.data || {};
                    publishTaskId = data.id;
                  } else {
                    this.$message.error(res.msg);
                  }
                  if (!publishTaskId) {
                    this.$message.error("下线失败");
                    this.loading = false;
                    return;
                  }
                  stopParams = {
                    publishTaskId: publishTaskId,
                  };
                  //   第二个接口开始，下线
                  this.handleOffLine(stopParams);
                },
                { once: true }
              );
            } else {
              const res = await this.$store.dispatch(
                "modelManagePublishtaskPublishTaskDataFindByModelId",
                params
              );
              const result = res.data || {};
              if (result.success) {
                const data = result.data || {};
                publishTaskId = data.id;
              }
              if (!publishTaskId) {
                this.$message.error("下线失败");
                this.loading = false;
                return;
              }
              stopParams = {
                publishTaskId: publishTaskId,
              };
              //   第二个接口开始，下线
              this.handleOffLine(stopParams);
            }
          } catch (e) {
            console.error(e);
          }
          this.loading = false;
        })
        .catch(() => {});
    },
    async handleOffLine(stopParams) {
      try {
        let res = {};
        let _self = this;
        if (_self.$qwebUtil.isQtClient) {
          const uuid = _self.$qwebUtil.generateRandomUUID();
          let sendObject;
          /* eslint-disable-next-line */
          const channel = new QWebChannel(
            window.qt.webChannelTransport,
            async function (channel) {
              sendObject = channel.objects.sendObject;
              // receivedJSON 修改此处发送请求参数
              const receivedJSON = {
                RequestUrl: `/publishtask/publish-task-data/${stopParams.publishTaskId}/stop`,
                RequestMethod: "post",
                ContentType: "application/json;charset=UTF-8",
                RequestBody: {},
                isStringParam: false,
                requestId: uuid,
              };
              await send();
              await _self.$qwebUtil.receive(sendObject, receivedJSON);
              // console.error('received','/feCanvas/pageList')
            }
          );
          /* eslint-disable-next-line */
          async function send() {
            sendObject.sendMessage.connect(function (data) {
              if (!data) {
                console.error("No data received.");
              }
              res = JSON.parse(data);
              const result = res.response || {};
              // update the followings
              if (result.success && res.webInfo.requestId == uuid) {
                _self.$message.success(result.msg);
                _self.init();
              } else {
                _self.$message.error(result.msg);
              }
            });
          }
        } else if (this.$webview2.isWPF) {
          const uuid = this.$webview2.generateRandomUUID();
          await this.$webview2.sendWebView2(
            `/publishtask/publish-task-data/${stopParams.publishTaskId}/stop`,
            "post",
            "application/json;charset=UTF-8",
            {},
            false,
            uuid
          );
          await window.chrome.webview.addEventListener(
            "message",
            (e) => {
              let res = e.data.response;
              console.log(res, e.data.webInfo.requestId === uuid);
              // TODO： 定制后台数据处理
              if (res.status === 200 && e.data.webInfo.requestId === uuid) {
                console.log(res, "stop");
                this.$message.success(res.msg);
                this.init();
              } else {
                // this.$message.error(res.msg);
              }
            }
            // { once: true }
          );
        } else {
          const res = await this.$store.dispatch(
            "modelManagePublishtaskPublishTaskDataIdStop",
            stopParams
          );
          const result = res.data || {};
          if (result.success) {
            this.$message.success(result.msg);
            this.init();
          } else {
            this.$message.error(result.msg);
          }
        }
      } catch (e) {
        this.$message.error(e);
        console.error(e);
      }
    },

    // 发布
    async publishOn(data) {
      if (data.projectType != "other") {
        this.flag = true;
        this.showClose = true;
        this.title = "发布模型";
        this.assembly = "发布模型";
        this.$nextTick(() => {
          this.$refs.publishModal && this.$refs.publishModal.show();
        });
      } else {
        // 其他类型
        const params = {
          modelId: data.modelId,
        };
        this.loading = true;
        try {
          let res = {};
          let _self = this;
          if (_self.$qwebUtil.isQtClient) {
            const uuid = _self.$qwebUtil.generateRandomUUID();
            let sendObject;
            /* eslint-disable-next-line */
            const channel = new QWebChannel(
              window.qt.webChannelTransport,
              async function (channel) {
                sendObject = channel.objects.sendObject;
                // receivedJSON 修改此处发送请求参数
                const receivedJSON = {
                  RequestUrl: "/publishtask/publish-task-data/publish",
                  RequestMethod: "post",
                  ContentType: "application/json;charset=UTF-8",
                  RequestBody: params,
                  isStringParam: false,
                  requestId: uuid,
                };
                await send();
                await _self.$qwebUtil.receive(sendObject, receivedJSON);
                // console.error('received','/feCanvas/pageList')
              }
            );
            /* eslint-disable-next-line */
            async function send() {
              sendObject.sendMessage.connect(function (data) {
                if (!data) {
                  console.error("No data received.");
                }
                res = JSON.parse(data);
                const result = res.response || {};
                // update the followings
                if (result.success && res.webInfo.requestId == uuid) {
                  _self.$message({
                    type: "success",
                    message: "发布成功",
                  });
                  _self.init();
                } else {
                  _self.$message({
                    type: "error",
                    message: result.msg || "发布失败",
                  });
                  _self.init();
                }
              });
            }
          } else if (this.$webview2.isWPF) {
            const uuid = this.$webview2.generateRandomUUID();
            await this.$webview2.sendWebView2(
              "/publishtask/publish-task-data/publish",
              "post",
              "application/json;charset=UTF-8",
              params,
              false,
              uuid
            );
            await window.chrome.webview.addEventListener("message", (e) => {
              let res = e.data.response;
              // TODO： 定制后台数据处理
              if (res.status === 200 && e.data.webInfo.requestId === uuid) {
                this.$message({
                  type: "success",
                  message: "发布成功",
                });
                this.init();
              } else {
                this.$message({
                  type: "error",
                  message: res.msg || "发布失败",
                });
                this.init();
              }
            });
          } else {
            const res = await this.$store.dispatch(
              "modelManagePublishtaskPublishTaskDataPublish",
              params
            );
            const result = res.data || {};
            if (result.success) {
              this.$message({
                type: "success",
                message: "发布成功",
              });
              this.init();
            } else {
              this.$message({
                type: "error",
                message: result.msg || "发布失败",
              });
              this.init();
            }
          }
        } catch (e) {
          console.error(e);
        }
        this.loading = false;
      }
    },

    // 发布-回调
    pushlishOnCallback() {
      // 禁用两秒
      let fullLoading = Loading.service({
        lock: true,
        text: "发布中",
      });
      setTimeout(() => {
        fullLoading.close();
        this.init();
      }, 3000);
    },
    // 进入
    checkProgress(isToModelResult = false) {
      const val = { ...this.originModelDetailData };
      const progressRate = val.progressRate || "";
      if (progressRate === "material") {
        this.$router.push({
          name: "addModel",
          params: {
            data: val,
            isToModelResult: isToModelResult,
          },
        });
      }
      if (progressRate === "publish" || isToModelResult) {
        this.$router.push({
          name: "addModel",
          params: {
            data: val,
            isToModelResult: true,
          },
        });
      }
      if (
        progressRate === "published" ||
        this.isTrainerr(this.modelDetailData)
      ) {
        this.$router.push({
          name: "addModel",
          params: {
            data: val,
            isToModelResult: true,
          },
        });
      }
    },

    // 无监督学习-下载
    async downloadUnFile() {
      this.downloading = true;
      try {
        let res = {};
        let _self = this;
        if (_self.$qwebUtil.isQtClient) {
          const uuid = _self.$qwebUtil.generateRandomUUID();
          let sendObject;
          /* eslint-disable-next-line */
          const channel = new QWebChannel(
            window.qt.webChannelTransport,
            async function (channel) {
              sendObject = channel.objects.sendObject;
              // receivedJSON 修改此处发送请求参数
              const receivedJSON = {
                RequestUrl: `/project/${_self.originModelDetailData.id}/getResultFile`,
                RequestMethod: "get",
                ContentType: "application/json;charset=UTF-8",
                RequestBody: {},
                isStringParam: false,
                requestId: uuid,
              };
              await send();
              await _self.$qwebUtil.receive(sendObject, receivedJSON);
              // console.error('received','/feCanvas/pageList')
            }
          );
          /* eslint-disable-next-line */
          async function send() {
            sendObject.sendMessage.connect(function (data) {
              // if (!data) {
              //   console.error("No data received.");
              // }
              // res = JSON.parse(data);
              // const result = res.response || {};
              // // update the followings
              // if (result.success && res.webInfo.requestId == uuid) {
              // } else {
              // }
            });
          }
        } else if (this.$webview2.isWPF) {
          const uuid = this.$webview2.generateRandomUUID();
          await this.$webview2.sendWebView2(
            `/project/${this.originModelDetailData.id}/getResultFile`,
            "get",
            "application/json;charset=UTF-8",
            {},
            false,
            uuid
          );
        } else {
          await this.$store.dispatch("proAdminProjectIdGetResultFile", {
            id: this.originModelDetailData.id,
          });
        }
      } catch (e) {
        console.error(e);
      }
      this.downloading = false;
    },

    // 模型下载
    async exportModel() {
      this.downloading = true;
      try {
        let res = {};
        let _self = this;
        if (_self.$qwebUtil.isQtClient) {
          const uuid = _self.$qwebUtil.generateRandomUUID();
          let sendObject;
          /* eslint-disable-next-line */
          const channel = new QWebChannel(
            window.qt.webChannelTransport,
            async function (channel) {
              sendObject = channel.objects.sendObject;
              // receivedJSON 修改此处发送请求参数
              const receivedJSON = {
                RequestUrl: `/training-model-data/model-data-sdk-list/${_self.modelId}`,
                RequestMethod: "get",
                contentType: "application/json;charset=UTF-8",
                RequestBody: {},
                isStringParam: false,
                requestId: uuid,
              };
              await send();
              await _self.$qwebUtil.receive(sendObject, receivedJSON);
              // console.error('received','/feCanvas/pageList')
            }
          );
          /* eslint-disable-next-line */
          async function send() {
            sendObject.sendMessage.connect(function (data) {
              // if (!data) {
              //   console.error("No data received.");
              // }
              // res = JSON.parse(data);
              // const result = res.response || {};
              // // update the followings
              // if (result.success && res.webInfo.requestId == uuid) {
              //   // const data = result.data;
              //   // _self.optionTableData =
              //   //   data.list && data.list.length ? data.list : [];
              //   // _self.optionTotal = data.rowCount || 0;
              // } else {
              //   // _self.optionTableData = [];
              //   // _self.optionTotal = 0;
              // }
            });
          }
        } else if (this.$webview2.isWPF) {
          const uuid = this.$webview2.generateRandomUUID();
          await this.$webview2.sendWebView2(
            `/training-model-data/model-data-sdk-list/${this.modelId}`,
            "get",
            "application/json;charset=UTF-8",
            {},
            true,
            uuid
          );
          await window.chrome.webview.addEventListener(
            "message",
            (e) => {
              let res = e.data.response;
              console.log(res);
              // TODO： 定制后台数据处理
              // if (res.status === 200 && e.data.webInfo.requestId === uuid) {
              // }
            },
            { once: true }
          );
        } else {
          await this.$store.dispatch(
            "modelManageTrainingModelDataModelDataSDKId",
            {
              id: this.modelId,
            }
          );
        }
      } catch (e) {
        console.error(e);
      }
      this.downloading = false;
    },

    isMaterial(row = {}) {
      return row.progressRate === "material";
    },
    isTrain(row = {}) {
      return row.progressRate === "train";
    },
    isPublish(row = {}) {
      return row.progressRate === "publish";
    },
    isPublished(row = {}) {
      return row.progressRate === "published";
    },
    isTrainerr(row = {}) {
      return row.progressRate === "trainerr";
    },
    isLoadmodel(row = {}) {
      return row.progressRate === "loadmodel";
    },
    statusPublished(row = {}) {
      return row.status === "published";
    },
    statusUnpublish(row = {}) {
      return row.status === "unpublish";
    },
    statusError(row = {}) {
      return row.status === "error";
    },
    statusPublishing(row = {}) {
      return row.status === "publishing";
    },
  },
};
</script>

<style lang="less" scoped>
.top {
  background: #ffffff;
  box-shadow: 0px 0px 3px 0px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  box-sizing: border-box;
  padding: 20px;
}

.bottom {
  background: #ffffff;
  box-shadow: 0px 0px 3px 0px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  box-sizing: border-box;
  padding: 20px;
  margin-top: 20px;
}

.bottom-title {
  width: 100%;
}

.bottom-title-name {
  font-family: PingFangSC-Medium;
  font-size: 16px;
  color: rgba(0, 0, 0, 0.75);
  line-height: 24px;
  font-weight: 500;
  margin: 0;
  display: inline-block;
}

.bottom-title-button {
  float: right;
}

.each-top-row {
  width: 100%;
  margin-bottom: 13px;
  display: flex;
  flex-wrap: wrap;
}

.each-top-row:last-of-type {
  margin-bottom: 0px;
}

.each-top-row .each-top-part {
  width: 33.3%;
  display: flex;
}

.each-top-row .each-top-part .each-top-part-name,
.each-top-row .each-top-part .each-top-part-value {
  font-family: PingFangSC-Regular;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.45);
  font-weight: 400;
}

.each-top-part-name {
  width: 130px;
  flex-shrink: 0;
  line-height: 28px;
  text-align: right;
  padding-right: 4px;

  &.col-0 {
    width: 105px;
  }

  &.col-2 {
    width: 75px;
  }
}

.each-top-part-value {
  flex-shrink: 1;
  line-height: 28px;
  word-break: break-all;
}

.each-top-row .each-top-part .each-top-part-value {
  color: rgba(0, 0, 0, 0.85);
}

.bottom-table-area {
  margin-top: 20px;
}

.flex-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  min-height: 28px;
}
</style>
